# Maintainer: Biswapriyo Nath <nathbappai@gmail.com>

_realname=yt-dlp
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2025.04.30
pkgrel=1
pkgdesc="A youtube-dl fork with additional features and fixes (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'archlinux: yt-dlp'
  'purl: pkg:pypi/yt-dlp'
)
url='https://github.com/yt-dlp/yt-dlp/'
license=('spdx:Unlicense')
depends=(
  "${MINGW_PACKAGE_PREFIX}-python-certifi"
  "${MINGW_PACKAGE_PREFIX}-python-websockets"
  "${MINGW_PACKAGE_PREFIX}-python-brotli"
  "${MINGW_PACKAGE_PREFIX}-python-mutagen"
  "${MINGW_PACKAGE_PREFIX}-python-urllib3"
  "${MINGW_PACKAGE_PREFIX}-python-pycryptodomex"
  "${MINGW_PACKAGE_PREFIX}-python-requests"
)
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-hatchling"
             "${MINGW_PACKAGE_PREFIX}-python-installer")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest")
optdepends=("${MINGW_PACKAGE_PREFIX}-aria2: for using aria2 as external downloader"
            "${MINGW_PACKAGE_PREFIX}-ffmpeg: for video post-processing")
options=('!strip')
source=("${_realname}-${pkgver}.tar.gz::https://github.com/yt-dlp/yt-dlp/releases/download/${pkgver}/yt-dlp.tar.gz")
sha256sums=('feb3113fc38c1c0f987d2cfcb7366fed65fa508ff302e7bd8ac9be87c7774b31')

build() {
  cp -r "${_realname}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"
  python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  python -m pytest || warning "Tests failed"
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
